#include "mycallback.h"

MyCallback::MyCallback(QObject *parent) :
    Sbs2Callback(parent)
{
    samplesToCollect = 4;
    samples = 0;
    valuesIndex = 0;
    for (int buffer = 0; buffer < 100; ++buffer)
    {
        values.append(QVector<QList<int> >());
        for (int i=0; i<2; ++i)
        {
            values[buffer].append(QList<int>());
            for (int k=0; k<this->samplesToCollect; ++k)
                values[buffer].last().append(0);
        }
    }

}

void MyCallback::getData(Sbs2Packet *packet)
{


    //always set pointer to the current packet
    thisPacket = packet;

    //increase and set counters
    currentPacketCounter =  packet->counter;
    ++ currentPacket;

    //always set the pointer to the packet in sbs2DataHandler
    sbs2DataHandler->setThisPacket(thisPacket);

    values[valuesIndex][0][samples] = thisPacket->filteredValues["O2"];
    values[valuesIndex][1][samples] = thisPacket->filteredValues["O2_2"];



    /*
    for (int i=0; i<Sbs2Common::channelsNo(); ++i)
    {
        values[valuesIndex][i][samples] = thisPacket->filteredValues[Sbs2Common::getChannelNames()->at(i)];
    }
    */

    ++samples;

    if (samples == samplesToCollect)
    {

        emit valueSignal(valuesIndex);
        valuesIndex = (valuesIndex+1)%values.size();
        samples = 0;
    }

}

